<?php
    //require section
    require_once dirname(__FILE__) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'check_session.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'check_outside_booking.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_cinemas.php';
    $title = 'Cinema Detail';

    $c_id = filter_input(INPUT_GET, 'c_id');
    if ($c_id != NULL) {
        $cinema = api_cinemas::get_cinema_by_id($c_id);
        $city   = api_cinemas::get_city_by_id($cinema['id']);
    } else {
        $cinema = NULL;
        $city   = NULL;
    }
?>

<!DOCTYPE html>
<html>
<head>
    <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
    ?>

    <script
        src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
    </script>

    <style>
        .gm-style-iw{
            width: 75px;
        }
    </style>
    <script>
        var myCenter = new google.maps.LatLng(<?php echo $cinema['latitude'] . ',' . $cinema['longitude']; ?>);

        function initialize() {
            var mapProp = {
                center: myCenter,
                zoom: 7,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);

            var marker = new google.maps.Marker({
                position: myCenter,
                animation: google.maps.Animation.BOUNCE
            });
            marker.setMap(map);
            <?php if($city != NULL): ?>
            var infowindow = new google.maps.InfoWindow({
                content: "<?php echo 'City: ' . $city['name']; ?>"
            });
            <?php endif; ?>
            infowindow.open(map, marker);
//            var myCity = new google.maps.Circle({
//                center: myCenter,
//                radius: 40000,
//                strokeColor: "#0000FF",
//                strokeOpacity: 0.8,
//                strokeWeight: 2,
//                fillColor: "#0000FF",
//                fillOpacity: 0.4
//            });
//            myCity.setMap(map);
        }

        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>
<body>
<div class="ts-body-container">
    <div class="ts-wrapper">
        <!--<div class="ui grid">-->
        <div class="padding-top-large row">
            <?php
                require_once DOCUMENT_ROOT . DIR_INCLUDE . 'header.php';
            ?>
            <div class="ui segment breadcrumb" style="margin-top: 25px; margin-left: 20px;">
                <a class="section" href="index.php">Home</a>
                <i class="right arrow icon divider"></i>
                <a class="section" href="cinema.php">Cinema</a>
                <i class="right arrow icon divider"></i>
                <div class="active section">Cinema Detail</div>
            </div>
        </div>
        <div class="ui grid" id="container">
            <div class="row">
                <div class="column">
                    <h1>Cinema Detail</h1>

                    <div class="ui orange segment">
                        <div class="row">
                            <div class="ts-detail-img-wrapper">
                                <?php if ($cinema != NULL) : ?>
                                    <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_CINEMAS . $cinema['image'] ?>">
                                <?php endif; ?>
                            </div>
                            <div class="ts-detail-info">
                                <table>
                                    <tr>
                                        <th>Name</th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <?php
                                                if ($cinema != NULL) {
                                                    echo $cinema['name'];
                                                }
                                            ?>
                                        </td>
                                    </tr>

                                    <tr>
                                        <th>City</th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <?php
                                                if ($city != NULL) {
                                                    echo $city['name'];
                                                }
                                            ?>
                                        </td>
                                    </tr>

                                    <tr>
                                        <th>Address</th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <?php
                                                if ($cinema != NULL) {
                                                    echo $cinema['address'];
                                                }
                                            ?>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div class="row" style="margin: 20px 0;">
                            <div id="googleMap" style="width:1065px;height:380px;"></div>
                        </div>
                        <div class="row">
                            <div class="ts-center">
                                <a href="<?php echo LINK_ROOT ?>" class="ui orange button">Back to Home Page</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <?php
                    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
                ?>
            </div>
            <!--</div>-->
        </div>
    </div>
</body>
</html>